<!doctype html>
<html class="no-js">
<head>
    <meta charset="UTF-8">
    <title>新闻列表 | 校园知事</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <link rel="stylesheet" href="/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/assets/css/admin.css">
    <link rel="stylesheet" href="/assets/css/appadmin.css">

	<style>
		.am-selected {
			width:100%;
		}
		.table-number{
			width:5%;
			text-align:center ;
		}
		.table-bigclass{
			width:7%;
			text-align:center
		}
		.table-smallclass{
			width:10%;
			text-align:center
		}
		.table-title{
			width:22%;
			text-align:center
		}
		.table-source{
			width:10%;
			text-align:center
		}
		.table-author{
			width:10%;
			text-align:center
		}
		.table-date{
			width:15%;
			text-align:center
		}
		.table-hits{
			width:6%;
			text-align:center
		}
		.table-set{
			width:15%;
			text-align:center
		}
	</style>
</head>
<body>
     {{template "admin/naver.html" .}}
        <!-- content start -->
        <div class="admin-content">
            <div class="admin-content-body">
                <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg"  style=" color: #222222;">新闻列表</strong></div>
                </div>
                <hr>
                <div class="am-g">
                    <div class="am-u-sm-12 am-u-md-3">
                         <div class="am-form-group am-margin-bottom-sm">
                            <select id="BigDropList" onchange="changeSmall(this)" data-am-selected="{btnSize: 'sm'}">
                               {{range $k,$v:=.BigList}}
                                        {{if $k}}
                                        <option value="{{$v.Id}}">{{$v.Name}}</option>
                                        {{else}}
                                        <option selected="selected" value="{{$v.Id}}">{{$v.Name}}</option>
                                        {{end}}
                                        {{end}}
                            </select>
                        </div>
                    </div>
					 <div class="am-u-sm-12 am-u-md-3 am-hide-sm-only">
                         <div class="am-form-group am-margin-bottom-sm">
                            <select id="SmallDropList" data-am-selected="{btnSize: 'sm'}">
                                <option value="0">所有</option>
                            </select>
                        </div>{{range $k,$v:= .SmallVal}}<input type="hidden" id="smallval{{$k}}" value="{{$v}}">{{end}}
                    </div>
                    <div class="am-u-sm-12 am-u-md-6">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" id="tmut" class="am-form-field" placeholder="标题关键字">
                            <span class="am-input-group-btn">
                                <button class="am-btn am-btn-default"  onclick="search()" type="button">搜索</button>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-12">
                            <table class="am-table am-table-striped am-table-hover table-main am-table-centered">
                                <thead>
                                    <tr>
						    <th class="table-number  am-hide-sm-only">编号</th>
                                        <th class="table-bigclass">大类别</th>
                                        <th class="table-smallclass am-hide-sm-only">小类别</th>
                                        <th class="table-title">新闻标题</th>
						    <th class="table-source am-hide-sm-only">新闻来源</th>
                                        <th class="table- author am-hide-sm-only">编辑</th>
                                        <th class="table-date ">修改日期</th>
						    <th class="table-hits">点击量</th>
                                        <th class="table-set">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        <div class="am-cf">
                        <div id="pageNav1" style="text-align:center"></div>
                        <p class="am-margin-top-sm" id="msg"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
     {{template "admin/footer.html" .}}
	<script src="/assets/laypage/laypage.js"></script>
    <script type="text/javascript">
        $(function(){
            _init(1,12);
        })
        function _init(pi,ps){
            $.AMUI.progress.start();
            $.post("/admin/article/list",{s:pi,c:ps,n:$("#tmut").val().trim(),b:$("#BigDropList").val(),sm:$("#SmallDropList").val()},function(data){
                if(data.status===1&&data.count>0){
                    var list='';
                   $.each(data.data,function(k,v){
                        list+='<tr><td>'+(k+1)+'</td>';
                        list+='<td>'+v.Bigclassname+'</td>';
                        list+='<td class="am-hide-sm-only">'+v.Smallclassname+'</td>';
                        list+='<td>'+v.Title+'</td>';
                        list+='<td class="am-hide-sm-only">'+v.Origin+'</td>';
                        list+='<td>'+v.Author+'</td>';
                        list+='<td>'+v.Context+'</td>';
                        list+='<td class="am-hide-sm-only">'+v.Hits+'</td>';
                        list+='<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">';
                        list+='<button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="javascript:window.location.href=\'/admin/article/edit/'+v.Id+'\'"><span class="am-icon-pencil-square-o"></span> 编辑</button>';
                        list+='<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-md-down"  onclick="del_art('+v.Id+')" ><span class="am-icon-trash-o"></span> 删除</button></div> </div> </td> </tr>';
                    });
                    $("tbody").html(list);
                     laypage({
                        cont: $('#pageNav1'),
                        pages: Math.ceil(data.count / ps),
                        curr: pi || 1,
                        skip: false,
                        jump: function (obj, first) {
                             $('#msg').html('注：第'+obj.curr+'/'+obj.pages+'页&nbsp;&nbsp;&nbsp;(共'+data.count +'条)');
                            if (!first) {
                                _init(obj.curr, ps);
                            }
                        }
                    });
                }else{
                $("tbody").html('');
                $('#pageNav1').html('未查询到相关信息');
                $('#msg').html('');
                }
            $.AMUI.progress.done();
            },"json")
        }
       function changeSmall(obj){
				var $thissmall=document.getElementById("smallval"+obj.value)
				if($thissmall=== null){
					 document.getElementById("SmallDropList").innerHTML="<option value='0'>无</option>"
				}else{
					document.getElementById("SmallDropList").innerHTML=document.getElementById("smallval"+obj.value).value
				}
            }
        function search(){
            _init(1,12);
        }
		 function del_art(i){
           var l= layer.confirm('你确定要删除吗？',{icon: 3, title:'警告',offset:'15%'},function(){
                layer.close(l);
                $.lintul('/admin/article/deletearticle',{id:i},function(data){
                 if (data.status === 1) {
                        layer.msg('删除成功', { offset: '15%', icon: 6 ,time:1000}, function () {
                            _init(Number($(".laypage_curr").text()),12);
                        });
                    } else {
                        layer.msg('删除失败,请检查后重试', { offset: '15%', icon: 5 });
                    }
            });
            });
        }
    </script>

</body>
</html>
